package cn.bytets.rpc.api;

import cn.bytets.rpc.common.URL;

/**
 * 这里只是测试方便所以把这个类设置为抽象类,其实想要动态加载Transporter接口的子类可以使用SPI加载
 */
public class Transporters{

    private Transporter transporter;

    private Transporters(){

    }
    public static Transporters getInstance(){
        return TransportersInstance.getTransporters();
    }
    public  RpcServer bind() {
        return transporter.bind();
    }

    public  RpcClient connect(URL url) {
        return transporter.connect(url);
    }

    /**
     * 这里可以通过SPI配置可扩展的实现类,主要为方便测试
     * @return
     */
    public Transporters setTransporters(Transporter transporter){
        this.transporter = transporter;
        return this;
    }
    private static class TransportersInstance{

        private final static Transporters transporters = new Transporters();

        public static Transporters getTransporters(){
            return transporters;
        }
    }
}
